// pages/tiankong/tiankong.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    items: "",
    id: 0,
    laststate: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let api = this.apichange(options.id);
    console.log(options.id)
    wx.request({
      url: `${app.globalData.apiurl}${api}/list`,
      method: "GET",
      data: {
        account: 10
      },
      success: res => {
        let count = res.data.length
        for (let i = 0; i < count; i++) {
          if (res.data[i].image !== "") {
            res.data[i].img = ""
            res.data[i].txt = "none"
          } else {
            res.data[i].img = "none"
            res.data[i].txt = ""
          }
          // if (res.data[i].answer == "A") {
          //   res.data[i].answer = ["dui", "cuo", "cuo", "cuo"]
          // }
          // if (res.data[i].answer == "B") {
          //   res.data[i].answer = ["cuo", "dui", "cuo", "cuo"]
          // }
          // if (res.data[i].answer == "C") {
          //   res.data[i].answer = ["cuo", "cuo", "dui", "cuo"]
          // }
          // if (res.data[i].answer == "D") {
          //   res.data[i].answer = ["cuo", "cuo", "cuo", "dui"]
          // }
        }
        console.log()
        this.setData({
          items: res.data
        })
      }
    })
  },
  apichange: function (id) {
    if (id == 5) {
      let name = "gqbSx1Completion"
      return name;
    }
    if (id == 6) {
      let name = "gqbSx1Solution"
      return name;
    }
    if (id == 8) {
      let name = "gqbSx2Completion"
      return name;
    }
    if(id == 15){
      let name = "gqzSx1Completion"
      return name;
    }
    if (id == 18) {
      let name = "gqzSx2Completion"
      return name;
    }
    if (id == 32) {
      let name = "zsbSx1Completion"
      return name;
    }
    if (id == 35) {
      let name = "zsbSx2Completion"
      return name;
    }
  },

  bindNext: function (e) {
    let state = this.data.state;
    state = ["none", "none", "none", "none"];
    this.setData({
      state: state,
      laststate: ""
    })
    if (this.data.id == 9) {
      wx.showToast({
        title: '已经做完10题！点左上角返回！',
        icon: "none"
      })
      return false;
    } else {
      let ide = this.data.id * 1 + 1
      console.log(ide)
      this.setData({
        id: ide,
        answer: this.data.items[ide].answer
      })
      console.log(this.data.items[this.data.id])
    }
  },
  //上一题点击事件
  bindLast: function (e) {
    let state = this.data.state;
    state = ["none", "none", "none", "none"];
    this.setData({
      state: state,
      analyze: "none",
    })
    if (this.data.id == 0) {
      this.setData({
        laststate: ""
      })
      return false;
    } else {
      let ide = this.data.id * 1 - 1
      this.setData({
        id: ide,
        answer: this.data.items[ide].answer
      })
      if (ide == 0) {
        this.setData({
          laststate: ""
        })
      }
      console.log(this.data.items[this.data.id])
    }
  },
  //点击预览图片
  pretitle: function (e) {
    let id = this.data.id
    console.log(this.data.items[id])
    wx.previewImage({
      urls: [this.data.items[id].image],
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})